﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using Padelcenter.Common;
using Padelcenter.DataAccess;

namespace Padelcenter.BusinessLogic
{
    public class GetZona : IBusinessLogic
    {
        public GetZona() { }

        public void Invoke()
        {
            Zona_Select oZonaSelect = new Zona_Select();
            oZonaSelect.Zona = this.Zona;
            this.Resultset = oZonaSelect.Get();
        }

        public List<Zona> ZonaList()
        {
            this.Invoke();

            List<Zona> listaZona = new List<Zona>();

            DataTable dTable = new DataTable();
            dTable = this.Resultset.Tables[0];

            if (dTable.Rows.Count > 0)
            {
                Zona oZona;
                foreach (DataRow r in dTable.Rows)
                {
                    oZona = new Zona();
                    
                    oZona.IdZona = Convert.ToInt32(r["idZona"]);
                    oZona.Descripcion = r["Descripcion"].ToString();

                    Moneda oMoneda = new Moneda();
                    oMoneda.IdMoneda = Convert.ToInt32(r["idMoneda"]);

                    GetMoneda oGetMoneda = new GetMoneda();
                    oGetMoneda.Moneda = oMoneda;

                    oZona.Moneda = oGetMoneda.MonedaList()[0];

                    oZona.Activo = Convert.ToBoolean(r["Activo"]);

                    listaZona.Add(oZona);
                }
            }

            return listaZona;
        }

        private DataSet _resultset;
        private Zona _zona;

        public Zona Zona
        {
            get { return _zona; }
            set { _zona = value; }
        }

        public DataSet Resultset
        {
            get { return _resultset; }
            set { _resultset = value; }
        }
    }
}
